package com.neusoft.care.controller;


import com.neusoft.care.po.CareLevel;
import com.neusoft.care.po.ResponseBean;
import com.neusoft.care.service.CareLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin("*")
@RequestMapping("/CareLevelController")
public class CareLevelController {

    @Autowired
    private CareLevelService careLevelService;

    @GetMapping("/getAllCareLevels")
//    查询护理等级列表（默认启用）
    public ResponseBean<List<CareLevel>> getAllCareLevels() {
        return careLevelService.getAllCareLevels();
    }

    @GetMapping("/{id}")
    public ResponseBean<CareLevel> getCareLevelById(@PathVariable Integer id) {
        return careLevelService.getCareLevelById(id);
    }

    @GetMapping("/getCareLevelByStatus")
//    根据状态查询护理级别
    public ResponseBean<List<CareLevel>> getCareLevelByStatus(@RequestParam String status) {
        return careLevelService.getAllCareLevelsByStatus(status);
    }

    @PostMapping("/addCareLevel")
//    添加护理级别（护理级别名称和状态）
    public ResponseBean<Integer> addCareLevel(@RequestBody CareLevel careLevel) {
        return careLevelService.addCareLevel(careLevel);
    }

    @PutMapping("/updateCareLevel")
//    修改护理级别，只能修改其状态
    public ResponseBean<Integer> updateCareLevel(@RequestBody CareLevel careLevel) {
        careLevel.setLevelId(careLevel.getLevelId());
        return careLevelService.updateCareLevel(careLevel);
    }

    @DeleteMapping("/{id}")
    public ResponseBean<Integer> deleteCareLevel(@PathVariable Integer id) {
        return careLevelService.deleteCareLevel(id);
    }
}